<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="24">

          <a-col :md="6" :sm="8">
            <a-form-item label="姓名">
              <a-input placeholder="请输入姓名" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>


          <a-col :md="6" :sm="8">
            <a-form-item label="学号">
              <a-input placeholder="请输入学号" v-model="queryParam.stuNo"></a-input>
            </a-form-item>
          </a-col>


          <a-col :md="6" :sm="8">
            <a-form-item label="批次">
              <!--<a-input placeholder="请输入批次" v-model="queryParam.batch"></a-input>-->
              <j-dict-select-tag @change="change($event,'batch')" :value="batch" v-decorator="['batch', {}]"
                                 :triggerChange="true" placeholder="请选择"
                                 dictCode="xc_batch"/>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="所属校区">
              <!--<a-input placeholder="请输入所属校区" v-model="queryParam.newSchool"></a-input>-->

              <j-dict-select-tag @change="change($event,'newSchool')" :value="newSchool" v-decorator="['batch', {}]"
                                 :triggerChange="true" placeholder="请选择"
                                 dictCode="xc_school"/>
            </a-form-item>


          </a-col>


          <a-col :md="6" :sm="8">
            <a-form-item label="报名学校">
              <a-select @change="schoolChange"  :options="optionsSchool" placeholder="请选择"
                        v-decorator="['toSchool', {}]">
              </a-select>
              <!--<a-input placeholder="请输入报名学校" v-model="queryParam.toSchool"></a-input>-->
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="层次">
              <j-dict-select-tag @change="change($event,'level')" :value="level" v-decorator="['level', {}]"
                                 :triggerChange="true" placeholder="请选择"
                                 dictCode="xc_level"/>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="8">
            <a-form-item label="学籍状态">
              <j-dict-select-tag @change="change($event,'eduStatus')" :value="eduStatus" v-decorator="['eduStatus', {}]"
                                 :triggerChange="true" placeholder="请选择"
                                 dictCode="xc_edu_status"/>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="24" >
            <a-form-item label="录取时间">
              <!--<a-input placeholder="请输入微信" v-model="wechat"></a-input>-->
              <a-date-picker @change="onChange"  showTime format="YYYY-MM-DD"  />
            </a-form-item>
          </a-col>



          <a-col :md="6" :sm="8">
            <a-form-item label="学习形式">
              <j-dict-select-tag @change="change($event,'learnType')" :value="learnType"
                                 v-decorator="['learnType', {}]" :triggerChange="true" placeholder="请选择"
                                 dictCode="xc_learn_type"/>
            </a-form-item>
          </a-col>





          <template v-if="toggleSearchStatus">


            <a-col :md="6" :sm="8">
            <a-form-item label="性别">
            <j-dict-select-tag @change="change($event,'sex')" :value="sex" v-decorator="['sex', {}]"
            :triggerChange="true" placeholder="请选择"
            dictCode="sex"/>
            <!--<a-input placeholder="请输入性别" v-model="queryParam.sex"></a-input>-->
            </a-form-item>
            </a-col>


            <a-col :md="6" :sm="8">
              <a-form-item label="身份证号">
                <a-input placeholder="请输入身份证号" v-model="queryParam.cardId"></a-input>
              </a-form-item>
            </a-col>



            <a-col :md="6" :sm="8">
              <a-form-item label="专业">
                <a-input placeholder="请输入专业" v-model="queryParam.major"></a-input>
              </a-form-item>
            </a-col>


            <a-col :md="6" :sm="8">
              <a-form-item label="所属平台">
                <j-dict-select-tag @change="change($event,'belong')" :value="belong" v-decorator="['belong', {}]"
                                   :triggerChange="true" placeholder="请选择"
                                   dictCode="xc_platform"/>
              </a-form-item>
            </a-col>


          </template>
          <a-col :md="6" :sm="8">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">刷新</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!--<a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>-->
      <div  v-has="'show:成教学生:导出'">
        <a-button  v-if="index==1" type="primary" icon="download" @click="handleExportXls('成教学生')">导出</a-button>
      </div>
      <div  v-has="'show:网教学生:导出'">
        <a-button v-if="index==2"  type="primary" icon="download" @click="handleExportXls('网教学生')">导出</a-button>
      </div>

      <div  v-has="'show:自考学生:导出'">
        <a-button v-if="index==3"  type="primary" icon="download" @click="handleExportXls('自考学生')">导出 </a-button>
      </div>



      <!--<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl"-->
      <!--@change="handleImportExcel">-->
      <!--<a-button type="primary" icon="import">导入</a-button>-->
      <!--</a-upload>-->
      <!--<a-dropdown  v-if="selectedRowKeys.length > 0">-->
      <a-dropdown v-if="false">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <!--<div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">-->
      <!--<i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项-->
      <!--<a style="margin-left: 24px" @click="onClearSelected">清空</a>-->
      <!--</div>-->

      <a-table
        :scroll="{ x: 2200 }"
        ref="table"
        size="middle"
        bordered
        rowKey="id+createTime"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <!--<a @click="handleEdit(record)">编辑</a>-->

          <!--<a-divider type="vertical"/>-->
          <a-dropdown>
            <a class="ant-dropdown-link">查看 <a-icon type="down"/></a>
            <a-menu slot="overlay">

               <a-menu-item>
                  <a @click="handleChoose(record)">院校信息</a>
              </a-menu-item>

              <a-menu-item>
                  <a @click="handleEduChange(record)">学籍异动记录</a>
              </a-menu-item>

              <a-menu-item>
                  <a @click="handleExamine(record)">成考信息</a>
              </a-menu-item>

              <a-menu-item>
                  <a @click="handlePlatform(record)">录取信息</a>
              </a-menu-item>

              <!--<a-menu-item>-->
                <!--<a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
                  <!--<a>删除</a>-->
                <!--</a-popconfirm>-->
              <!--</a-menu-item>-->
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <div style="display: none">
    <studentRelChoose-modal ref="modalForm" @ok="modalFormOk"></studentRelChoose-modal>
    <school-choose-modal ref="schoolChooseModal"></school-choose-modal>
    <school-choose-list ref="schoolChooseList"></school-choose-list>
    <edu-change-modal ref="eduChangeModal"></edu-change-modal>
    <edu-change-list ref="eduChangeList"></edu-change-list>
      <edu-change-list-modal ref="eduChangeModalList"></edu-change-list-modal>
    <platform-modal ref="platformModal"></platform-modal>
    <platform-list ref="platformList"></platform-list>
    <examine-modal ref="examineModal"></examine-modal>
    <examine-list ref="examineList"></examine-list>
    </div>
  </a-card>
</template>

<script>
  import StudentRelChooseModal from './modules/StudentRelChooseModal'
  import ExamineModal from '@/views/xuecheng/student/modules/ExamineModal'
  import ExamineList from '@/views/xuecheng/student/ExamineList'
  import EduChangeModal from '@/views/xuecheng/student/modules/EduChangeModal'
  import EduChangeList from '@/views/xuecheng/student/EduChangeList'
  import EduChangeListModal from '@/views/xuecheng/student/modules/EduChangeListModal'
  import PlatformModal from '@/views/xuecheng/student/modules/PlatformModal'
  import PlatformList from '@/views/xuecheng/student/PlatformList'
  import SchoolChooseModal from '@/views/xuecheng/student/modules/SchoolChooseModal'
  import SchoolChooseList from '@/views/xuecheng/student/SchoolChooseList'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import { initDictOptions, filterDictText } from '@/components/dict/JDictSelectUtil'
  import { getAction } from '@/api/manage'

  import { filterObj } from '@/utils/util';

  export default {
    name: 'StudentRelChooseList',
    mixins: [JeecgListMixin],
    components: {
      StudentRelChooseModal,
      SchoolChooseModal,
      EduChangeModal,
      PlatformModal,
      ExamineModal,
      SchoolChooseList,
      ExamineList,
      EduChangeList,
      PlatformList,
      EduChangeListModal
    },
    data() {
      return {
        description: '学生一览表管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            fixed: 'left',
            customRender: function(t, r, index) {
              return parseInt(index) + 1
            }
          },

          {
            title: '姓名',
            align: 'center',
            dataIndex: 'name',
            width: 100,
            fixed: 'left'
          },
          {
            title: '学号',
            align: 'center',
            width: 130,
            dataIndex: 'stuNo'

          },
          {
            title: '性别',
            align: 'center',
            dataIndex: 'sex',
            width: 100,
            customRender: (text, record, index) => {
              //字典值替换通用方法
              if (this.sexDictOptions === '') return ''
              return filterDictText(this.sexDictOptions, text)
            }
          },
          {
            title: '身份证号',
            align: 'center',
            width: 130,
            dataIndex: 'cardId'

          },
          {
            title: '批次',
            align: 'center',
            width: 100,
            dataIndex: 'batch'
          },
          {
            title: '所属校区',
            align: 'center',
            width: 100,
            dataIndex: 'newSchool',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              if (this.schoolDictOptions === '') return ''
              let result = filterDictText(this.schoolDictOptions, text);
              if(result===''){
                return text
              }else{
                return result
              }
            }
          },
          {
            title: '学籍状态',
            align: 'center',
            width: 100,
            dataIndex: 'eduStatus',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              if (this.eduStatusDictOptions === '') return ''
              return filterDictText(this.eduStatusDictOptions, text)
            }
          },
          {
            title: '联系电话',
            align: 'center',
            width: 120,
            dataIndex: 'phone'
          },
          {
            title: '报名学校',
            align: 'center',
            width: 200,
            dataIndex: 'toSchool'
          },
          {
            title: '层次',
            align: 'center',
            width: 100,
            dataIndex: 'level',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              if (this.levelDictOptions === '') return ''
              let result = filterDictText(this.levelDictOptions, text);
              if(result===''){
                return text
              }else{
                return result
              }
            }
          },
          {
            title: '专业',
            align: 'center',
            width: 150,
            dataIndex: 'major'
          },
          {
            title: '学习形式',
            align: 'center',
            width: 100,
            dataIndex: 'learnType',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              if (this.learnTypeDictOptions === '') return ''
              let result = filterDictText(this.learnTypeDictOptions, text);
              if(result===''){
                return text
              }else{
                return result
              }
            }

          },
          {
            title: '所属平台',
            align: 'center',
            width: 140,
            dataIndex: 'belong',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              if (this.platformStatusDictOptions === '') return ''
              let result = filterDictText(this.platformStatusDictOptions, text);
              if(result===''){
                return text
              }else{
                return result
              }
            }
          },
          {
            title: '平台账号',
            align: 'center',
            width: 150,
            dataIndex: 'platformAcount'
          },
          {
            title: '平台密码',
            align: 'center',
            width: 150,
            dataIndex: 'platformPwd'
          },
          {
            title: '录取日期',
            align: 'center',
            width: 150,
            dataIndex: 'enrollTime'
          },
          {
            title: '报名时间',
            align: 'center',
            width: 150,
            dataIndex: 'createTime',
            customRender: (text, record, index) => {
              //字典值替换通用方法
              if (text!== ''&&text!=null) {
                return text.substring(0,11);
              }else {
                return ""
              }
            }
          },
          {
            title: '操作',
            width: 100,
            dataIndex: 'action',
            align: 'center',
            fixed:'right',
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: '/studentRelChoose/studentRelChoose/list',
          delete: '/studentRelChoose/studentRelChoose/delete',
          deleteBatch: '/studentRelChoose/studentRelChoose/deleteBatch',
          exportXlsUrl: 'studentRelChoose/studentRelChoose/exportXls',
          importExcelUrl: 'studentRelChoose/studentRelChoose/importExcel'
        },
        sex: '',
        sexDictOptions: '',
        level: '',
        levelDictOptions: '',
        learnType: '',
        learnTypeDictOptions: '',
        eduStatusDictOptions: '',
        belong: '',
        batch:'',
        platformStatusDictOptions: '',
        queryParam:{
        },
        isLoad:false,
        newSchool:'',
        schoolDictOptions:'',
        optionsSchool:[],
        toSchool:'',
        eduStatus:'',
        enterTime:'',
        index:''
      }
    },
    computed: {
      importExcelUrl: function() {
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
      }
    },

    watch: {
      '$route': function(newRoute) {
        let path = newRoute.path
        if (path.indexOf('/studentRelChoose/studentRelChoose/list/') !== -1) {
          let index = path.substring(path.length - 1, path.length)
          this.queryParam.learnType = index
          this.index=index
        } else {
          this.queryParam.learnType = ''
          this.index=''
        }

        this.loadData(1,this.isLoad)
      },
      // 'queryParam.learnType': function(learnType) {
      //   this.queryParam.learnType = learnType
      //   this.loadData(1)
      //   console.log('learnType----->', learnType)
      // }
      'queryParam': function(learnType) {
        // this.queryParam.learnType = learnType
        this.index=learnType.learnType
        this.loadData(1,this.isLoad)
        console.log('learnType----->', learnType)
      },

    },
    created() {
      this.initDictConfig()

      this.initOptionsSchool()
    },
    mounted() {
      this.isLoad=true
      let path = this.$route.path
      if (path.indexOf('/studentRelChoose/studentRelChoose/list/') !== -1) {
        let index = path.substring(path.length - 1, path.length)
        this.queryParam.learnType = index
        this.queryParam=Object.assign({},this.queryParam)

      } else {
        this.queryParam.learnType = ''
        this.queryParam=Object.assign({},this.queryParam)
      }

    },
    methods: {
      // 刷新
      searchReset() {
        // this.queryParam = {}
        this.loadData(1,this.isLoad);
      },
      handleTableChange(pagination, filters, sorter) {
        //分页、排序、筛选变化时触发
        //TODO 筛选
        if (Object.keys(sorter).length > 0) {
          this.isorter.column = sorter.field;
          this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
        }
        console.log("pagination---->",pagination)
        this.ipagination = pagination;
        this.loadData(100,this.isLoad);
      },

      onChange(data,dateString){
        console.log("data---->",data)
        this.enterTime=dateString
      },

      // 选择学校
      schoolChange(value, text, options) {
        this.queryParam.toSchool=value

      },

      // 加载报考学校
      initOptionsSchool() {
        var url = '/school/school/listAll'
        getAction(url).then((res) => {
          if (res.success) {
            var result = res.result
            result.forEach(r => {
              this.optionsSchool.push({
                value: r.schoolName,
                label: r.schoolName,
              })
            })
          }
        })
      },
      searchQuery(){
        if(this.enterTime!==''){
          this.queryParam.enrollTime = this.enterTime
        }
        this.loadData(1,true)
      },
      getQueryParams(learnType) {
        //获取查询条件
        let sqp = {}
        if(this.superQueryParams){
          sqp['superQueryParams']=encodeURI(this.superQueryParams)
        }
        var param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters);
        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        param.learnType=this.queryParam.learnType;
        // return filterObj(param);
        return param;
      },

      loadData(arg,isLoad){
        console.log(111)

        if(isLoad){
          if(!this.url.list){
            this.$message.error("请设置url.list属性!")
            return
          }
          //加载数据 若传入参数1则加载第一页的内容
          if (arg === 1) {
            this.ipagination.current = 1;
          }
          var params = this.getQueryParams();//查询条件
          this.loading = true;
          getAction(this.url.list, params).then((res) => {
            if (res.success) {
              this.dataSource = res.result.records;
              this.ipagination.total = res.result.total;
            }
            if(res.code===510){
              this.$message.warning(res.message)
            }
            this.loading = false;
          })
        }

      },
      // 查看院校报考
      handleChoose(record) {
       this.getRecord(record.id, this.$refs.schoolChooseList.url.list,"choose")
      },
      // 查看学籍异动
      handleEduChange(record) {
        this.getRecord(record.id, this.$refs.eduChangeList.url.list,"edu")
      },
      // 录取信息
      handlePlatform(record) {
        this.getRecord(record.id, this.$refs.platformList.url.list,"platform")
      },

      // 成考管理
      handleExamine(record) {
        this.getRecord(record.id, this.$refs.examineList.url.list,"exam")


      },

      getRecord(mainId,urlList,type){
        getAction(urlList, { mainId: mainId }).then((res) => {
          if (res.success) {
            // 如果有多于一个报考信息，则不让他显示 新增按钮
            // this.dataSource = res.result
            let record=res.result[0]

            switch (type) {
              case 'choose':
                this.$refs.schoolChooseModal.edit(record,'d')
                this.$refs.schoolChooseModal.title = '详情'
                this.$refs.schoolChooseModal.disableSubmit = true

                break;
              case 'edu':
                // this.$refs.eduChangeModal.edit(record)
                // this.$refs.eduChangeModal.title = '详情'
                // this.$refs.eduChangeModal.disableSubmit = true
                console.log("33333333333333333->",mainId)
                this.$refs.eduChangeModalList.getMain(mainId)
                break;
              case 'platform':
                this.$refs.platformModal.edit(record)
                this.$refs.platformModal.title = '详情'
                this.$refs.platformModal.disableSubmit = true
                break;
              case 'exam':
                this.$refs.examineModal.edit(record)
                this.$refs.examineModal.title = '详情'
                this.$refs.examineModal.disableSubmit = true
                break;
            }
          } else{
            console.log("发生错误！")
          }
        })
      },
      initDictConfig() {
        //初始化字典 - 性别
        initDictOptions('sex').then((res) => {
          if (res.success) {
            this.sexDictOptions = res.result
          }
        })

        initDictOptions('xc_level').then((res) => {
          if (res.success) {
            this.levelDictOptions = res.result
          }
        })
        initDictOptions('xc_learn_type').then((res) => {
          if (res.success && res.result !== '') {
            this.learnTypeDictOptions = res.result
          }
        })
        initDictOptions('xc_edu_status').then((res) => {
          if (res.success) {
            this.eduStatusDictOptions = res.result
          }
        })

        initDictOptions('xc_platform').then((res) => {
          if (res.success && res.result !== '') {
            this.platformStatusDictOptions = res.result
          }
        })


        initDictOptions('xc_school').then((res) => {
          if (res.success && res.result !== '') {
            this.schoolDictOptions = res.result
          }
        })
      },
      change(value, text) {
        console.log('value----->', value)
        if (text === 'sex') {
          this.sex = value
          this.queryParam.sex = value
        } else if (text === 'level') {
          this.level = value
          this.queryParam.level = value
        } else if (text === 'learnType') {
          this.learnType = value
          this.queryParam.learnType = value
        } else if (text === 'belong') {
          this.belong = value
          this.queryParam.belong = value
        }else if (text === 'batch') {
          this.batch = value
          this.queryParam.batch = value
        }else if (text === 'newSchool') {
          this.newSchool = value
          this.queryParam.newSchool = value
        }else if (text === 'eduStatus') {
          this.eduStatus = value
          this.queryParam.eduStatus = value
        }

      }

    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>